package com.towker.frame.controller.warehouse;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.towker.core.page.PageModel;
import com.towker.core.page.PageNav;
import com.towker.frame.model.basicData.Depots;
import com.towker.frame.model.basicData.Goods;
import com.towker.frame.model.warehouse.GoodsAllocates;
import com.towker.frame.service.basicData.DepotsService;
import com.towker.frame.service.basicData.GoodsService;
import com.towker.frame.service.warehouse.GoodsInOutService;
import com.towker.frame.share.sys.user.UserShare;
import com.towker.web.MyRequest;

@Controller
@RequestMapping("/manage/warehouse")
public class GoodsInOutController {
	private GoodsInOutService service;
	private GoodsService goodsService;
	private DepotsService depotsService;
	
	public void setGoodsInOutService(GoodsInOutService service) {
		this.service = service;
	}

	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}

	public void setDepotsService(DepotsService depotsService) {
		this.depotsService = depotsService;
	}
	//账面明细
	@RequestMapping("/getGoodsInOutList")
	public ModelAndView getWarehouseAccountsList(HttpServletRequest request, HttpServletResponse response, @RequestParam(value="page", defaultValue="1")int page)
	{
		int pageSize = 10;
		MyRequest req = new MyRequest(request);
		String goodsSn = req.getString("goodsSn");
		String depotCode = req.getString("depotCode");
		Goods goods = goodsService.getByGoodsSn(goodsSn);
		Depots depot = depotsService.getByCode(depotCode);
		Map map = req.getParameterValueMap(false, true);
		//只查询当前用户所属部门
		map.put("authCoCode", UserShare.getCurrentUserCoCode(request));
		//map.put("authDepCode", UserShare.getCurrentUserDepCode(request));
		PageModel<GoodsAllocates> pageModel = service.getPage(page, pageSize, map);
		int preAmount = service.getPreCount(map, page, pageSize);
		PageNav pageNav = new PageNav(request, pageModel);
		ModelAndView result = new ModelAndView();		
		result.addObject("pageModel", pageModel);
		result.addObject("pageNav", pageNav);
		result.addObject("preAmount", preAmount);
		result.addObject("goods", goods);
		result.addObject("depot", depot);
		result.setViewName("/manage/warehouse/getGoodsInOutList.jsp");
		return result;
	}
}
